set dotenv-load := true
set shell := ["bash", "-uc"]

package_name := "{{ cookiecutter.package_module }}"
python_min_version := "{{ cookiecutter.min_python_version }}"
python_max_version := "{{ cookiecutter.max_python_version }}"
python_dev_version := python_min_version
pypi_server_url := "{{ cookiecutter.pypi_server_url | replace('/simple/', '') | replace('/simple', '') | replace('/$', '') }}"

init:
    uv sync --all-groups
    uvx pre-commit install

lint:
    uvx ruff check --fix .
    uvx ruff format .
    uvx ruff check .

lint-add-noqa:
    uvx ruff check --add-noqa .
    just lint-pre-commit
    just lint

lint-pre-commit:
    uvx pre-commit run --all-files

lint-watch:
    uvx ruff check --watch .

test:
    just test-version {% raw %}{{python_dev_version}}{% endraw %}

test-all:
    for version in $(python -c "min_ver = '{% raw %}{{python_min_version}}{% endraw %}'.split('.'); max_ver = '{% raw %}{{python_max_version}}{% endraw %}'.split('.'); [print(f'{min_ver[0]}.{minor}') for minor in range(int(min_ver[1]), int(max_ver[1]) + 1)]"); do just test-version "$version"; done

test-version version:
    echo "Testing with Python {% raw %}{{version}}{% endraw %}..."
    uv run --all-groups --python {% raw %}{{version}}{% endraw %} pytest --cov={% raw %}{{package_name}}{% endraw %} --cov-report=xml --cov-report=term-missing -v packages/*/tests/

test-watch:
    uv run --all-groups ptw --runner "pytest -vx packages/*/tests/"

docs:
    uv run --group docs mkdocs serve

docs-build:
    uv run --group docs mkdocs build

deploy-gh-pages:
    uv run --group docs mkdocs gh-deploy --force

build:
    uv build --all-packages

publish-pypi:
    uv publish dist/*

publish-pypi-server:
    UV_PUBLISH_USERNAME="${PYPI_SERVER_USERNAME}" UV_PUBLISH_PASSWORD="${PYPI_SERVER_PASSWORD}" UV_PUBLISH_URL="${PYPI_SERVER_URL:-{% raw %}{{pypi_server_url}}{% endraw %}}" uv publish dist/*

publish-all:
    just publish-pypi
    just publish-pypi-server

deploy-pypi:
    just build
    just publish-pypi

deploy-pypi-server:
    just build
    just publish-pypi-server

deploy-all:
    just build
    just publish-all

export-deps:
    uv export --no-hashes --output-file requirements.txt
